﻿Imports QuanLyCafe.NhanVien_BUS

Public Class QuanLyNhanVien
    Private Sub bntQuayLai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntQuayLai.Click
        Me.Close()
    End Sub

    Private Sub QuanLyNhanVien_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CenterToScreen()
        'Dim ds As DataTable = New DataTable()
        'ds = GetListNV_BUS()
        'gvDSNhanVien.DataSource = ds
        HienThiNV()
        Clear()
    End Sub

    Public Sub HienThiNV()
        Dim dt As DataTable = New DataTable()
        dt = GetListNV_BUS()
        gvDSNhanVien.DataSource = dt
    End Sub

    Public Sub TaoNV(ByVal nv As NhanVien_DTO)
        nv.MaNhanVien = txtMaSoNV.Text
        nv.TenNhanVien = txtHoTen.Text
        nv.CMNhanDan = txtCMND.Text
        nv.SDienThoai = txtSoDT.Text
        nv.CVu = txtChucVu.Text
        nv.QQuan = txtQueQuan.Text
        If rbnNam.Checked = True Then
            nv.GTinh = "Nam"
        Else
            nv.GTinh = "Nu"
        End If
        nv.NSinh = dtpNgaySinh.Value
    End Sub

    Private Sub gvDSNhanVien_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gvDSNhanVien.SelectionChanged
        'txtMaSoNV.Text = gvDSNhanVien.CurrentRow.Cells(0).Value.ToString()
        'txtHoTen.Text = gvDSNhanVien.CurrentRow.Cells(1).Value.ToString()
        'txtCMND.Text = gvDSNhanVien.CurrentRow.Cells(2).Value.ToString()
        'txtSoDT.Text = gvDSNhanVien.CurrentRow.Cells(4).Value.ToString()
        'txtChucVu.Text = gvDSNhanVien.CurrentRow.Cells(7).Value.ToString()
        'txtQueQuan.Text = gvDSNhanVien.CurrentRow.Cells(3).Value.ToString()
        'Dim gtinh As String = gvDSNhanVien.CurrentRow.Cells(5).Value.ToString()
        'If gtinh = "Nam" Then
        '    rbnNam.Checked = True
        'Else
        '    rbnNu.Checked = True
        'End If
        'Dim ngSinh As String = gvDSNhanVien.CurrentRow.Cells(6).Value.ToString()
        'dtpNgaySinh.Text = Date.Parse(ngSinh.ToString())

        txtMaSoNV.Text = gvDSNhanVien.CurrentRow.Cells(0).Value.ToString()
        txtHoTen.Text = gvDSNhanVien.CurrentRow.Cells(1).Value.ToString()
        txtCMND.Text = gvDSNhanVien.CurrentRow.Cells(2).Value.ToString()
        txtChucVu.Text = gvDSNhanVien.CurrentRow.Cells(6).Value.ToString()
        txtQueQuan.Text = gvDSNhanVien.CurrentRow.Cells(3).Value.ToString()
        Dim gtinh As String = gvDSNhanVien.CurrentRow.Cells(4).Value.ToString()
        If gtinh = "Nam" Then
            rbnNam.Checked = True
        Else
            rbnNu.Checked = True
        End If
        Dim ngSinh As String = gvDSNhanVien.CurrentRow.Cells(5).Value.ToString()
        dtpNgaySinh.Text = Date.Parse(ngSinh.ToString())
    End Sub

    Private Sub btnThemNhanVien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemNhanVien.Click
        Dim nv As NhanVien_DTO = New NhanVien_DTO()
        TaoNV(nv)
        InsertNV_BUS(nv)
        HienThiNV()
    End Sub

    Public Sub Clear()
        txtChucVu.Clear()
        txtCMND.Clear()
        txtHoTen.Clear()
        txtMaSoNV.Clear()
        txtQueQuan.Clear()
        txtSoDT.Clear()
        dtpNgaySinh.ResetText()
        rbnNam.Checked = True
    End Sub

    Private Sub btnSuaNhanVien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuaNhanVien.Click
        Dim nv As NhanVien_DTO = New NhanVien_DTO()
        TaoNV(nv)
        'nv.MaNhanVien = txtMaSoNV.Text
        'nv.TenNhanVien = txtHoTen.Text
        'nv.CMNhanDan = txtCMND.Text
        'nv.SDienThoai = txtSoDT.Text
        'nv.CVu = txtChucVu.Text
        'nv.QQuan = txtQueQuan.Text
        'If rbnNam.Checked = True Then
        '    nv.GTinh = "Nam"
        'Else
        '    nv.GTinh = "Nu"
        'End If
        'nv.NSinh = dtpNgaySinh.Value
        UpdateNV_BUS(nv)
        HienThiNV()
    End Sub

    Private Sub bntXoaNHanVien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntXoaNHanVien.Click
        Dim nv As NhanVien_DTO = New NhanVien_DTO()
        TaoNV(nv)
        DeleteNV_BUS(nv)
        HienThiNV()
    End Sub
End Class